﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.AnalysisServices.SharePoint.Integration;

namespace UpdatePowerPivot
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteURL = "http://yoursitecollectionurl/";
            string powerPivotDocumentURL = "http://yourfullurlpowerpivodocument.xlsx";
            GeminiServiceApplicationProxy proxy = null;
            DataRefreshSchedule refreshSchedule = null;
            try
            {
                Console.WriteLine("Connect...");
                proxy = CustomDataRefreshUtils.GetDefaultProxy(siteURL);
            }
            catch (DataRefreshException dataRefreshException)
            {
                Console.WriteLine("Error to connect with Geminis!!");
            }

            try
            {
                Console.WriteLine("Retrieve schedule...");
                refreshSchedule = CustomDataRefreshUtils.GetRefreshScheduls(powerPivotDocumentURL, true);

                Console.WriteLine("Persist refresh...");
                proxy.PersistDataRefreshSchedule(refreshSchedule);
            }
            catch (DataRefreshException dataRefreshException)
            {
                Console.WriteLine("Error to refresh!!");
            }

            Console.WriteLine("Refresh enqueue sucesfully :)  press enter...");
            Console.ReadLine();
        }

    }
}
